package com.guchenbo.example.bit;

/**
 * Created by CreGu on 2016/6/14.
 */
public class Test {

    public static String bytes2HexString(byte[] b) {
        String ret = "";
        for (int i = 0; i < b.length; i++) {
            String hex = Integer.toHexString(b[i] & 0xFF);
            if (hex.length() == 1) {
                hex = '0' + hex;
            }
            ret += hex.toUpperCase();
        }
        System.out.println(ret);
        return ret;
    }

    public static void main(String[] args) {
        int i = -130;
        byte b = (byte) i;

        System.out.println(b);

        int i2 = b;
        System.out.println(i2);

        i = 255;
        b = (byte) i;

        System.out.println(b);

        i2 = b;
        System.out.println(i2);

        System.out.println(Integer.toHexString(-128));

        byte b2 = -128;
        System.out.println(b2);
        System.out.println(Integer.toHexString(-128 & 0xff));

        byte[] bs = new byte[10];
        bs[0] = -128;
        bytes2HexString(bs);
        m();

        byte b22= (byte) 129;
        System.out.println(b22&0xff);

        byte b3 = -1;
        System.out.println(Integer.toBinaryString((byte)b3));

        System.out.println(Integer.toBinaryString(-1&0xff));
    }

    public static void m(){
        boolean boo=true;
        byte b = 127;
        short s=128;
        char c='t';
        int i=200;
        double d=2.2;
        float f=222222222222.222222222f;
        long l=20l;

        short s2=b;
        int i2 = b;
        long l2=i;
        int i22 = (int) l;
    }
}
